package com.atguigu.srb.core.controller.api;

import com.atguigu.srb.core.service.UserInfoService;
import com.atguigu.srb.core.service.WxLoginService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/api/wx")
public class ApiWxLoginController {
    @Resource
    WxLoginService wxLoginService;

    @GetMapping("login")
    public String wxLogin(HttpSession session) {

        return wxLoginService.wxLogin(session);

    }

    //此方法回调 wx用户已确认授权，他希望得到的响应结果是 登录成功的页面
//code=091OnB000GtYHP1JTV100Ycznq3OnB0Q&state=3d6be0a4035d839573b04816624a415e
    @GetMapping("/callback")
    public String callback(String code, //用户授权后的临时票据
                           String state,//防止csrf跨站点攻击的唯一字符串
                           HttpSession session,
                           HttpServletRequest request) {
        return wxLoginService.callback(code,state,session,request);
    }
}
